package com.itcam.otcbackend.demo;

import static org.apache.commons.lang3.ArrayUtils.swap;

/**
 * @author : Cammy.Wu
 * Description : 
 */

public class SelectionSort {
    public static void main(String[] args) {
        int[] arr = {101, 34, 119, 1};
        selectionSort(arr);
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    private static void selectionSort(int[] nums) {
        for (int left = 0; left < nums.length; left++) {
            int min = left;
            for (int i = left + 1; i < nums.length; i++) {
                if (nums[i] < nums[min]) {
                    min = i;
                }
            }
            swap(nums, left, min);
        }
    }
}
